//
//  QCSegmentedCollectionCell.swift
//  SegmentedView
//
//  Created by lizhi on 2021/12/13.
//

import UIKit
import SnapKit

class QCSegmentedCollectionCell: UICollectionViewCell {
    public private(set) lazy var   titleLabel:UILabel = {
        let label = UILabel()
        
        return label
    }()
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        setup()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setup()  {
        self.addSubview(titleLabel)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        titleLabel.snp.makeConstraints {
//            $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
            $0.centerY.equalToSuperview()
            $0.height.equalTo(30)
            $0.leading.equalTo(10)
            $0.trailing.equalTo(-10)
            
        }
    }
    
//    override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
//        let font = UIFont.systemFont(ofSize: 14)
//           let size = self.titleLabel.text?.size(withAttributes: [NSAttributedString.Key.font: font]) ?? CGSize.zero
//           let att = super.preferredLayoutAttributesFitting(layoutAttributes);
//           att.frame = CGRect(x: 0, y: 0, width: size.width+50, height: 22)
//           self.titleLabel.frame = CGRect(x: 0, y: 0, width: att.frame.size.width, height: 22)
//           return att;
//       }
}
